package com.linkhub.oms.admin.modules.system.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import com.linkhub.oms.admin.modules.system.domain.param.EmailCodeParam;
import com.linkhub.oms.admin.modules.system.domain.param.SystemSignInParam;
import com.linkhub.oms.admin.modules.system.domain.param.SystemSignUpParam;
import com.linkhub.oms.admin.modules.system.domain.vo.LhTokenInfoDTO;
import com.linkhub.oms.admin.modules.system.domain.vo.RegisterInfoVO;
import com.linkhub.oms.admin.modules.system.service.SystemService;
import com.linkhub.oms.common.response.DataResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Description: SystemController
 * @Author: echo
 * @Date: 2024/3/6 14:43
 * @Version: 1.0
 */
@Slf4j
@RestController
@Api(tags = {"系统模块接口"})
@SaIgnore
public class SystemController {


    @Resource
    private SystemService systemService;

    @ApiOperation("获取邮箱验证码接口")
    @PostMapping("/email/code")
    public DataResponse<Void> sendEmailCode(@Valid @RequestBody EmailCodeParam emailCode) {
        systemService.sendEmailCode(emailCode);
        return DataResponse.success();
    }

    @ApiOperation("注册接口")
    @PostMapping("/sign/up")
    public DataResponse<RegisterInfoVO> signUp( @Valid @RequestBody SystemSignUpParam signUpParam) {
        return DataResponse.success(systemService.signUp(signUpParam));
    }

    @ApiOperation("登录接口")
    @PostMapping("/login")
    public DataResponse<LhTokenInfoDTO> login(@Valid @RequestBody SystemSignInParam signInParam) {
        return DataResponse.success(systemService.login(signInParam));
    }

    @ApiOperation("重置密码接口")
    @PostMapping("/reset/cipher")
    public DataResponse<Void> resetCipher(@Valid @RequestBody SystemSignUpParam signUpParam) {
        systemService.resetCipher(signUpParam);
        return DataResponse.success();
    }

    @ApiOperation("登出接口")
    @PostMapping("/logout")
    public DataResponse<Void> logout() {

        StpUtil.logout();
        return DataResponse.success();
    }


}
